<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('项目立项列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>项目编号：</label>
                                <input type="text" name="orderNo" autoComplete="off"/>
                            </li>
                            <li>
                                <label>单位名称：</label>
                                <input type="text" name="customerName" autoComplete="off"/>
                            </li>
                            <li>
                                <label>项目名称：</label>
                                <input type="text" name="name" autoComplete="off"/>
                            </li>
                            <li>
                            	<label>项目所属：</label>
                            	<select name="authority">
                            		<option value="">---全部---</option>
									<option th:each="cl:${deptlis}" th:value="${cl.deptId}" th:text="${cl.deptName}"></option>
								</select>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
            	<a class="btn btn-success" onclick="$.operate.addTab()" shiro:hasPermission="gcgl:project:add">
                    <i class="fa fa-plus"></i> 添加新项目
                </a>
<!--                 <a class="btn btn-success single disabled" onclick="editFapiao()" shiro:hasPermission="gcgl:project:add"> -->
<!--                     <i class="fa fa-plus"></i> 申请发票 -->
<!--                 </a> -->
                <!-- 
                <a class="btn btn-success single disabled" onclick="addjgzl()" shiro:hasPermission="gcgl:project:add">
                    <i class="fa fa-plus"></i> 上传竣工资料
                </a>
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="gcgl:project:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="gcgl:project:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="gcgl:project:remove">
                    <i class="fa fa-remove"></i> 删除
                </a> 
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="gcgl:project:export">
                    <i class="fa fa-download"></i> 导出
                </a> 
                -->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('gcgl:project:edit')}]];
        var againeditFlag = [[${@permission.hasPermi('gcgl:project:againedit')}]];
        var removeFlag = [[${@permission.hasPermi('gcgl:project:remove')}]];
//         var datas = [[${@dict.getType('gcgl_cbpg_status')}]];
        var datas = [[${@dict.getType('sj_contract_status')}]];
        var datasproType = [[${@dict.getType('sj_proType')}]];
        var datasgongs = [[${@dict.getType('sj_gongs')}]];
        var prefix = ctx + "gcgl/project";
        
		function editFapiao() {
			table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            
            if (rows.length > 1) {
                $.modal.alertWarning("请只选择一条记录");
                return;
            }
            
			var status = $.table.selectColumns("status");
            
            if(status==3){
            	$.modal.openTab('提交发票',"/gcgl/sqkp/add/"+rows.join());
            }else{
            	$.modal.alertWarning("该记录未审核通过！");
                return;
            }
        }
		
        function detail(projectId) {
            $.modal.openTab('打开',"/gcgl/project/detail/"+projectId);
        }
        
		//上传竣工资料
	    function addjgzl(){
	    	table.set();
        	var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
            if (rows.length == 0) {
                $.modal.alertWarning("请至少选择一条记录");
                return;
            }
            if (rows.length > 1) {
                $.modal.alertWarning("请务选择多条记录");
                return;
            }
            
            var status = $.table.selectColumns("status");
            
            if(status==3){
            	$.modal.open('项目竣工资料',"/gcgl/sgazhtjgzl/addYs/"+rows.join());
            }else{
            	$.modal.alertWarning("该记录未审核通过！");
                return;
            }
	    }
		
        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                detailUrl: prefix + "/detail/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "项目立项",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '序号',
                    width: "50px"
                },
                {
                    field: 'orderNo',
                    title: '项目编号',
                    width: "100px"
                },
                {
                    field: 'name',
                    title: '项目名称'
                },
                {
                    field: 'customerName',
                    title: '建设单位',
                    width: "200px"
                },
                {
                    field: 'authorityName',
                    title: '项目所属',
                    width: "90px"
                },
                {
                    field: 'yearStr',
                    title: '项目年份'
                },
                {
                    field: 'proType',
                    title: '项目类型',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(datasproType, item.proType);
		            },
                    width: "90px"
                },
                {
                    field: 'ztdw',
                    title: '主体公司',
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(datasgongs, item.ztdw);
		            },
                    width: "90px"
                },
                {
		            field: 'status',
		            title: '状态',
		            align: "left",
		            formatter: function(value, item, index) {
		            	return $.table.selectDictLabel(datas, item.status);
		            },
                    width: "90px"
		        },
                {
                    title: '操作',
                    align: 'center',
                    width: "250px",
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        if(row.status==1){
//                         	actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="traceProcess(\'' + row.processInstanceId + '\')" ><i class="fa fa-area-chart"></i>流程图</a>&nbsp;');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="run(\'' + row.processInstanceId + '\')"><i class="fa fa-file-archive-o"></i>流程进度</a>&nbsp;');
							actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a> ');
                        }else{
//                             actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="traceProcess(\'' + row.processInstanceId + '\')" ><i class="fa fa-area-chart"></i>流程图</a>&nbsp;');
                            actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="run(\'' + row.processInstanceId + '\')"><i class="fa fa-file-archive-o"></i>流程进度</a>&nbsp;');
                        }
//                         if(row.status!=4){
//                         	actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="sqkp(\'' + row.id + '\',\''+ row.status +'\')"><i class="fa fa-plus"></i>申请开票</a> ');
//                         }
                        actions.push('<a class="btn btn-success btn-xs ' + againeditFlag + '" href="javascript:void(0)" onclick="$.operate.editTab(\'' + row.id + '\')"><i class="fa fa-edit"></i>更正</a> ');
                        actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="$.operate.detailTab(\'' + row.id + '\')"><i class="fa fa-plus"></i>查看</a> ');
//                         actions.push('<a class="btn btn-danger btn-xs href="javascript:void(0)" onclick="showForm(\''+ row.name + '\',\''+ row.processInstanceId +'\')"><i class="fa fa-envelope-open"></i>撤回</a>&nbsp;');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });
        
        function showForm(name, projectId) {
            $.modal.openTab(name , "/gcgl/project/modify4ch/"+ projectId);
        }
        
        function sqkp(projectId,status) {
            console.log(status);
            if(status>2){
            	$.modal.openTab('申请开票',"/gcgl/sqkp/add/"+projectId);
            }else{
            	$.modal.alertWarning("该记录未审核通过！");
                return;
            }
        }
        
        function run(processInstanceId) {
            $.modal.open("执行记录", ctx + "flow/monitor/historyDetail?processInstanceId=" + processInstanceId);
        }
        
        function traceProcess(processInstanceId) {
            $.modal.openTab("流程进度", ctx + "flow/monitor/traceProcess/"+processInstanceId);
        }
    </script>
</body>
</html>